IF exists(SELECT * FROM dbo.sysobjects WHERE name='maakHulpKlasRooster' AND xtype='P') 
BEGIN
	DROP PROCEDURE maakHulpKlasRooster
END
GO

create procedure maakHulpKlasRooster
as
delete from hulpKlasRooster

insert into hulpKlasRooster( deKlas,uur, maandag, dinsdag, woensdag, donderdag, vrijdag )
select l.klas,u.uur, ' ',' ',' ',' ',' '
from uren as u, klasLeraars as l
order by l.klas,u.uur

update hulpKlasRooster
set maandag = m.hetLokaal,dinsdag = d.hetLokaal,woensdag = w.hetLokaal,donderdag = do.hetLokaal,vrijdag=v.hetLokaal
from  hulpKlasRooster as u 
	left join (select top 100 percent * from rooster 
		where deDag = 'Ma'
		order by deKlas) as m
	  on u.Uur = m.hetUur and u.deKlas = m.deKlas
 	left join (select top 100 percent * from rooster 
		where deDag = 'Di'
		order by deKlas) as d	  
	  on u.Uur = d.hetUur and u.deKlas = d.deKlas 
	left join (select top 100 percent * from rooster 
		where deDag = 'Wo'
		order by deKlas) as w
	  on u.Uur = w.hetUur and u.deKLas = w.deKLas
 	left join (select top 100 percent * from rooster 
		where deDag = 'Do'
		order by deKlas) as do
	  on u.Uur = do.hetUur and u.deKlas = do.deKlas 
	left join (select top 100 percent * from rooster 
		where deDag = 'Vr'
		order by deKlas) as v
	  on u.Uur = v.hetUur and u.deKLas = v.deKlas